﻿// poetry.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "dataBase.h"
#include "people.h"
#include "teacher.h"
#include "student.h"
#include<fstream>
using namespace std;
#include <windows.h>

#pragma comment(lib, "winmm.lib")
bool music(bool m) {                //用于播放音乐
	if (m == true)
	{
		PlaySound(TEXT("1.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);//LOOP是循环的意思
		return false;
	}
	if (m == false)
	{
		PlaySound(NULL, NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);//LOOP是循环的意思
		return true;
	}
}
int main()
{
	bool musi=true;//音乐判断
	dataBase a;//建立数据库
	people *x=new people;
	teacher tech;
	student stu;

	while (1)
	{
		system("cls");
		cout << "-----------------------------------------------------\n";
		cout << "|                   唐诗三百首                      |\n";
		cout << "-----------------------------------------------------\n";
		cout << "-----------------------------------------------------\n";
		cout << "|                 选择登陆方式:                     |\n";
		cout << "|                   1、管理员                       |\n";
		cout << "|                   2、学员                         |\n";
		cout << "-----------------------------------------------------\n";
		cout << "|                   3、播放/停止音乐                |\n";
		cout << "-----------------------------------------------------\n";
		cout << "请选择:";
		string p;
		cin >> p;
		if (p == "1")//老师
		{
			x = &tech;
			while (1)
			{
				cout << "请输入密码:";
				ifstream file("adminpass.dat", ios::in);
				string f;
				getline(file, f, '\n');
				string pass;
				cin >> pass;
				if (pass == f)
				{
					system("cls");
					while (1)
					{
						system("cls");
						cout << "-----------------------------------------------------\n";
						cout << "|                   唐诗三百首                      |\n";
						cout << "-----------------------------------------------------\n";
						cout << "-----------------------------------------------------\n";
						cout << "|                   选择方式:                        |\n";
						cout << "|                   1、学习                          |\n";
						cout << "|                   2、查看记录                      |\n";
						cout << "|                   3、查看收藏                      |\n";
						cout << "|                   4、返回                          |\n";
						cout << "-----------------------------------------------------\n";
						cout << "请选择:";
						string tem;
						cin >> tem;
						if (tem == "1")//学习
						{
							x->get_admin_user("admin");
							system("cls");
							x->poetry_study(a, true);
						}
						else if (tem == "2")//查看记录
						{
							x->get_admin_user("admin");
							system("cls");
							x->user_list(a);
							cout << "输入任意数返回:";
							string anjian;
							cin >> anjian;
						}
						else if (tem == "3")//查看收藏
						{
							x->get_admin_user("admin");
							system("cls");
							x->scang(a);
							cout << "输入任意数返回:";
							string anjian;
							cin >> anjian;
						}
						else if (tem == "4")break;
					}
				}
				else
				{
					cout << "密码错误！" << endl;
					continue;
				}
				break;
			}
		}
		else if (p == "2")//学生
		{
			x = &stu;
			system("cls");
			cout << "-----------------------------------------------------\n";
			cout << "|                   唐诗三百首                      |\n";
			cout << "-----------------------------------------------------\n";
			cout << "-----------------------------------------------------\n";
			cout << "|                   选择方式:                        |\n";
			cout << "|                   1、登陆                          |\n";
			cout << "|                   2、注册新用户                    |\n";
			cout << "-----------------------------------------------------\n";
			cout << "请选择:";
			string yi;
			cin >> yi;
			if (yi == "1")
			{

				x->getin();
				while (1)
				{
					system("cls");
					cout << "-----------------------------------------------------\n";
					cout << "|                   唐诗三百首                      |\n";
					cout << "-----------------------------------------------------\n";
					cout << "-----------------------------------------------------\n";
					cout << "|                   选择方式:                        |\n";
					cout << "|                   1、学习                          |\n";
					cout << "|                   2、查看记录                      |\n";
					cout << "|                   3、查看收藏                      |\n";
					cout << "|                   4、返回                          |\n";
					cout << "-----------------------------------------------------\n";
					cout << "请选择:";
					string fi;
					cin >> fi;
					if (fi == "1")
					{
						system("cls");
						x->poetry_study(a, true);
					}
					else if (fi == "2")
					{
						system("cls");
						x->user_list(a);
						cout << "输入任意数返回:";
						string anjian;
						cin >> anjian;
					}
					else if (fi == "3")
					{
						system("cls");
						x->scang(a);
						cout << "输入任意数返回:";
						string anjian;
						cin >> anjian;
					}
					else if (fi == "4")
					{
						break;
					}
				}
			}
			else if (yi =="2")//注册
			{
				x->add_userdata();
				while (1)
				{
					system("cls");
					cout << "-----------------------------------------------------\n";
					cout << "|                   唐诗三百首                      |\n";
					cout << "-----------------------------------------------------\n";
					cout << "-----------------------------------------------------\n";
					cout << "|                   选择方式:                        |\n";
					cout << "|                   1、学习                          |\n";
					cout << "|                   2、查看记录                      |\n";
					cout << "|                   3、查看收藏                      |\n";
					cout << "|                   4、返回                          |\n";
					cout << "-----------------------------------------------------\n";
					cout << "请选择:";
					string fi;
					cin >> fi;
					if (fi == "1")
					{
						system("cls");
						x->poetry_study(a, true);
					}
					else if (fi == "2")
					{
						system("cls");
						x->user_list(a);
						cout << "输入任意数返回:";
						string anjian;
						cin >> anjian;
					}
					else if (fi == "3")
					{
						system("cls");
						x->scang(a);
						cout << "输入任意数返回:";
						string anjian;
						cin >> anjian;
					}
					else if (fi == "4")
					{
						break;
					}
				}
				//system("cls");
				//x->poetry_study(a,true);
			}
			
		}
		else if (p=="3")
		{
			musi=music(musi);
			system("cls");
			continue;
		}
	}
	return 0;
}
